<template>
  <div  >
    <el-row class="comment-box" v-if="listData.length" >
       <el-col  v-for="(item, index) in listData" :key="index" >
        <div class="comment">
          <div class="left">
            <el-image class="img" :src="item.avatarUrl" />
          </div>
          <div class="center">
            <div class="name">{{ item.name }}</div>
            <div class="describe">{{ item.status==='AGREE'?'参与中':item.status==='WAITING'?'待审核':item.status==='REJECT'?'已拒绝':'' }}</div>
          </div>
          <div class="flex-box" v-if="item.status==='WAITING'" style="padding-right:8px">
            <div class="time">{{ item.createTime }}</div>
            <el-button
              type="success"
              style="width: 74px"
              size="mini"
              class="btn-color"
              @click="replyListStatu(item,'AGREE')"
            >通过</el-button>
          </div>

          <div class="flex-box">
           <!-- {{commentType}} -->
            <div class="time">{{ item.createTime }}</div>
            <el-button style="width:74px" size="mini"
             @click="$set(item,'edit',true)"
             v-if="(item.status!=='CANCELED'||!item.hasEvaluation)&&item.status==='AGREE'&&commentType!=='WEB_CAST'">
            评价
            </el-button>
            <el-button v-else-if="item.status==='WAITING'"
              style="width: 74px"
              size="mini"
              @click="replyListStatu(item,'REJECT')"
            >拒绝</el-button>
            <el-button v-else-if="item.status==='CANCELED'||item.hasEvaluation"
              style="width: 74px"
              size="mini"
              type="text"

            >已评价</el-button>
          </div>
        </div>
        <div
          v-if="item.edit&&item.status!=='CANCELED'"
          class="clearfix"
          style="padding: 0 40px 50px 204px"
        >
        <Star :list='item' @scoreCanbank="scoreCanbank"/>

          <el-input
            v-model="replyCommentTxt"
            class="comment-val"
            type="textarea"
            :rows="3"
            placeholder="说点什么吧…"
            resize="none"
          />
          <div class="fr marginT20">
            <el-button
              type="success"
              class="btn-color fs-14"
              style="width: 120px; height: 36px;"
              size="small"
              @click="saveEvaluate(replyCommentTxt, item, index)"
            >发布评价</el-button>
          </div>
        </div>
      </el-col>
    </el-row>
    <div v-else class="comment-box text-center" v-noData></div>
  </div>
</template>

<script>
import { commentPage, comment, replyPage } from '@/api/basic'
import {saveEvaluate,enrollAudit} from '@/api/activity'
import Star from './Star'
var locApi = {
  "code": "string",
  "data": {
    "records": [
      {
        "activityParticipantId": 0,
        "avatarUrl": "https://yes910-pub.obs.cn-south-1.myhuaweicloud.com/mi/1280078522743808001/avatar/82fb3d02905d4302811abe259a092d42.jpg",
        "hasEvaluation": true,
        "name": "老林的新歌",
        "titleUrl": "哈哈是的",
        "userId": 0
      }
    ],
    "total": 0
  },
  "msg": "string",
  "timestamp": 0,
  "trace": "string"
}
export default {
  name: 'Comment',
  props: ['list', 'commentType','evaluateType'],
  data () {
    return {
      listData: this.list,
      subjectType: this.commentType,
      evaluateTypes: this.evaluateType || 'owner_to_viewer',
      commentTxt: null, // 评论
      replyCommentTxt: null, // 回复评论
      replyCommentInx: null, // 回复索引
      indScore:0,
      commentPageQuery: {
        condition: {
          keyword: null,
          status: null,
          subjectId: null,
          subjectType: this.commentType,
          userId: null
        },
        pager: {
          page: 1,
          pageSize: 20
        }
      },
      commentPageList: null,
      commentPageTotal: null,
      commentPageOpen: 4
    }
  },
  components:{
    Star
  },
  computed: {
  },
  watch: {
  },
  created () {
    console.log('commentType:', this.commentType)
    //this.getCommentPage()
  },
  methods: {
    //5 start code
      scoreCanbank(score){
          this.indScore = score
      },
        //---end

     async saveEvaluate(content,item,index){
       var params = {
        "activityId": this.$route.query.activityId,
        content,
        "evaluateType": this.evaluateTypes,
        //"pid": 123,
        userId:item.userId,
        "score": this.indScore
      }
       let res  = await saveEvaluate(params)
        this.$set(item,'status','CANCELED')
      },
      replyListStatu(item,status){
        var pass = status!=='REJECT'

        enrollAudit({
          enrollId:item.enrollId,
          pass
        }).then((res)=>{
          this.$set(item,'status',status)
        })
      }
  }
}
</script>

<style lang='scss' scoped>
.comment-box {
  margin-top: 24px;
  background-color: white;
  border-radius: 16px;
  padding: 40px 0;

  .comment-val {
    border-radius: 8px;
  }
  .comment {
    border-top: 1px solid #dbdadd;
    padding: 15px 0;
    display: flex;
    position: relative;

    .left {
      position: relative;
      padding-left:20px;
      padding-right: 16px;
      .img {
        width: 58px;
        height: 58px;
        border-radius: 50%;
        overflow: hidden;
      }
    }
    .left:after {
      content: "";
      display: block;
      clear: both;
      width: 100%;
      height: 3px;
      background-color: white;
      position: absolute;
      bottom: -41px;
      left: 0;
      z-index: 10;
    }
    .center {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      overflow: hidden;
      padding-right: 15px;
      .name {
        font-size: 16px;
        font-family: AppleSystemUIFont;
        color: rgba(0, 0, 0, 0.85);
        line-height: 24px;
      }
      .describe {
        font-size: 16px;
        font-family: AppleSystemUIFont;
        color: rgba(0, 0, 0, 0.45);
        line-height: 24px;
        display: flex;
        span {
          display: block;
          color: rgba(0, 0, 0, 0.85);
        }

        span:last-child {
          flex: 1;
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }
    .right {
      padding-right: 40px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: flex-end;
      .time {
        font-size: 16px;
        font-family: AppleSystemUIFont;
        color: rgba(0, 0, 0, 0.25);
        line-height: 24px;
      }
    }
  }

  .replyComment {
    padding-left: 84px;

    .left:after {
      left: -84px;
    }
  }
  .more-txt {
    position: absolute;
    left: 50%;
    bottom: 0;
    color: #54b87b;
    cursor: pointer;
    padding: 4px 10px;
  }
  .more {
    border-top: 1px solid #dbdadd;
    cursor: pointer;
    margin-top: 5px;
    padding-top: 40px;
    text-align: center;
    font-size: 16px;
    font-family: AppleSystemUIFont;
    color: rgba(84, 184, 123, 1);
    line-height: 24px;
  }
}
</style>
